/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import Entidades.User;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author Jhon
 */
public class UserDAO {
    static private UserDAO ArchivosDAO = null;
    private UserDAO() {}
    static public UserDAO getSingleton() {
        if (ArchivosDAO == null) {
        ArchivosDAO = new UserDAO();
        }
        return ArchivosDAO;
    }
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("UploadAndSaveTestPU2");


    public List<User> read() {
        EntityManager em = emf.createEntityManager();

        em.getTransaction().begin();

        try {
            Query q = em.createQuery("SELECT u FROM User u");

            return q.getResultList();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }

        return null;
    }
}
